import unittest
from Vector2D import Vector2D

################################################################################
class MyTestCase(unittest.TestCase):
    """
    MyTestCase Class - Tests for class Vector2D
    """    
    ############################################################################
    def testA(self):
        """ 
        testA - Make sure constructor stored initial values properly and 
            we can get them with the accessors
        """
        oVector = Vector2D(5,7.5)
        assert oVector.X() == 5, "X does not equal 5?"
        assert oVector.Y() == 7.5, "Y does not equal 7.5?"
    ############################################################################
    
    ############################################################################
    def testB(self):
        """ 
        testB - Test overridden operators 
        """
        
        # '+' operator
        TestVector = Vector2D(2,4.5) + Vector2D(8.5,1.3)
        assert TestVector.X() == 10.5 and TestVector.Y() == 5.8, "'+' operator failed adding two Vectors, X = " + str(TestVector.X()) + ", Y = " + str(TestVector.Y())
        TestVector = [8.5,1.3] + Vector2D(2,4.5)
        assert TestVector.X() == 10.5 and TestVector.Y() == 5.8, "'+' operator failed adding list to a Vector, X = " + str(TestVector.X()) + ", Y = " + str(TestVector.Y())
        
        # '+=' operator
        TestVector = Vector2D(3,4)
        TestVector += Vector2D(6,7)
        assert TestVector.X() == 9 and TestVector.Y() == 11, "'+=' operator failed adding Vector, X = " + str(TestVector.X()) + ", Y = " + str(TestVector.Y())
        TestVector += [4.5,1.1]
        assert TestVector.X() == 13.5 and TestVector.Y() == 12.1, "'+=' operator failed adding list, X = " + str(TestVector.X()) + ", Y = " + str(TestVector.Y())
        
        # '-' operator
        TestVector = Vector2D(12,14.5) - Vector2D(8.5,1.3)
        assert TestVector.X() == 3.5 and TestVector.Y() == 13.2, "'-' operator failed subtracting two Vectors, X = " + str(TestVector.X()) + ", Y = " + str(TestVector.Y())
        TestVector = [8.5,5.5] - Vector2D(2,4.5)
        assert TestVector.X() == 6.5 and TestVector.Y() == 1, "'-' operator failed subtracting list from a Vector, X = " + str(TestVector.X()) + ", Y = " + str(TestVector.Y())
        
        # '-=' operator
        TestVector = Vector2D(3,4)
        TestVector -= Vector2D(6,7)
        assert TestVector.X() == -3 and TestVector.Y() == -3, "'-=' operator failed subtracting Vector, X = " + str(TestVector.X()) + ", Y = " + str(TestVector.Y())
        TestVector -= [45,1.1]
        assert TestVector.X() == -48 and TestVector.Y() == -4.1, "'-=' operator failed subtracting list, X = " + str(TestVector.X()) + ", Y = " + str(TestVector.Y())
        
        # '*' operator
        TestVector = Vector2D(2,4.5) * 3
        assert TestVector.X() == 6 and TestVector.Y() == 13.5, "'*' operator failed, X = " + str(TestVector.X()) + ", Y = " + str(TestVector.Y())
        
        # '*=' operator
        TestVector = Vector2D(3,4)
        TestVector *= 2
        assert TestVector.X() == 6 and TestVector.Y() == 8, "'*=' operator failed, X = " + str(TestVector.X()) + ", Y = " + str(TestVector.Y())
        
        # '/' operator
        TestVector = Vector2D(9,15) / 3
        assert TestVector.X() == 3 and TestVector.Y() == 5, "'/' operator failed, X = " + str(TestVector.X()) + ", Y = " + str(TestVector.Y())
                
        # '/=' operator
        TestVector = Vector2D(7,4)
        TestVector /= 2
        assert TestVector.X() == 3.5 and TestVector.Y() == 2, "'/=' operator failed, X = " + str(TestVector.X()) + ", Y = " + str(TestVector.Y())
    ############################################################################
    
    ############################################################################
    def testC(self):
        """ 
        testC - Test Zero Functions
        """
        oVector = Vector2D(5,7.5)
        assert oVector.IsZero() == False, "Vector should not be reported Zero"
        oVector.Zero()
        assert oVector.IsZero() == True, "Vector should be reported Zero"
    ############################################################################
    
    ############################################################################
    def testD(self):
        """ 
        testD - Test Length Functions
        """
        oVector = Vector2D(3,4)
        assert oVector.LengthSq() == 25, "Unexpected Length Square, LengthSq = " + str(oVector.LengthSq())
        assert oVector.Length() == 5, "Unexpected Length, Length = " + str(oVector.Length())
    ############################################################################
################################################################################

if __name__ == "__main__":
    unittest.main() # run all tests